package com.tonicgb.service;

import com.tonicgb.service.constracts.UploadService;
import com.tonicgb.shared.common.response.FileResult;
import com.tonicgb.shared.util.UploadLocalUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Service("local")
public class UploadLocalService implements UploadService {
    @Autowired
    private UploadLocalUtil uploadLocalUtil;
    @Override
    public FileResult image(MultipartFile multipart, String Model, Integer pid) throws Exception {
            if(StringUtils.isNotBlank(Model))
             uploadLocalUtil.setModelPath(Model);
        return uploadLocalUtil.image(multipart);

    }

    @Override
    public FileResult file(MultipartFile multipart, String Model, Integer pid) throws IOException, Exception {
        if(StringUtils.isNotBlank(Model))
        uploadLocalUtil.setModelPath(Model);
        return uploadLocalUtil.file(multipart);
    }
}
